package com.sky.controller.admin;

import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import com.sky.vo.SetmealVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequiredArgsConstructor
@RequestMapping("/admin/setmeal")
@RestController
@Api(tags = "套餐管理")
public class SetmealController {
    private final SetmealService setmealService;

    @ApiOperation("分页查询")
    @GetMapping("page")
    public Result<PageResult> selectSetmealPage(SetmealPageQueryDTO dto) {
        PageResult result = setmealService.selectSetMealPage(dto);
        return Result.success(result);

    }

    @PostMapping
    @ApiOperation("新增套餐")
    public Result add(@RequestBody SetmealDTO dto) {
        setmealService.add(dto);
        return Result.success();
    }

    @GetMapping("/{id}")

    @ApiOperation("根据id查询套餐")
    public Result<SetmealVO> selectById(@PathVariable Long id) {
        SetmealVO setmealVO = setmealService.selectSetmealById(id);
        return Result.success(setmealVO);
    }

    @PutMapping
    @ApiOperation("修改套餐")
    public Result update(@RequestBody SetmealDTO dto) {
        setmealService.updateSetmeal(dto);
        return Result.success();
    }

    @DeleteMapping
    @ApiOperation("批量删除套餐")
    public Result deleteBatch(@RequestParam("ids") List<Long> ids) {
        setmealService.deleteBatch(ids);
        return Result.success();
    }
    @PostMapping("/status/{status}")
    @ApiOperation("起售、停售套餐")
    public Result startOrStop(@PathVariable Integer status, Long id) {
        setmealService.startOrStop(status, id);
        return Result.success();
    }
}
